//
//  Mine_DraftsViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 2016/12/5.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Mine_DraftsViewController.h"

#import "Mine_DraftsTableViewCell.h"
#import "DraftsDetailViewController.h"

@interface Mine_DraftsViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;

@end

@implementation Mine_DraftsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"草稿箱";
    _topView.backgroundColor = navi_bar_bg_color;
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 100, 15)];
    lbl_return.text = @"我";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 100, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //右编辑
    UIButton * btn_eidt = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_eidt.frame = CGRectMake(SCREEN_WIDTH - 5 - 50, 20 + 7, 50, 30);
    [btn_eidt setTitle:@"编辑" forState:(UIControlStateNormal)];
    [btn_eidt setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    btn_eidt.titleLabel.font = [UIFont systemFontOfSize:18];
    [_topView addSubview:btn_eidt];
    [btn_eidt addTarget:self action:@selector(btn_eidtAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//右侧编辑
- (void)btn_eidtAction:(UIButton *)sender
{
    NSLog(@"点击页面");
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[Mine_DraftsTableViewCell class] forCellReuseIdentifier:@"cell_Drafts"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Mine_DraftsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_Drafts" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.content.text = @"发日志";
    cell.time.text = @"几分钟前";
    cell.detail.text = @"核心数据";
    
    cell.btn_send.tag = indexPath.row + 1000;
    [cell.btn_send addTarget:self action:@selector(btn_sendAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSLog(@"跳转内容详情页面");
    
    DraftsDetailViewController * draftsDetailViewController = [[DraftsDetailViewController alloc] init];
    [self showViewController:draftsDetailViewController sender:nil];
}

#pragma mark - 点击发送
- (void )btn_sendAction:(UIButton *)sender
{
//    NSInteger number = sender.tag - 1000;
//    NSLog(@"%ld",number);
    
    NSLog(@"点击发送");
}

#pragma mark - 左滑删除
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"点击删除，掉接口");
}



















@end
